<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Queries the remote side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.socket-getpeername" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">socket_getpeername</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.1.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">socket_getpeername</span> &mdash; <span class="dc-title">Queries the remote side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.socket-getpeername-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>socket_getpeername</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$socket</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter reference">&$address</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter reference">&$port</code></span>
  ] ) : <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Queries the remote side of the given socket which may either result in
   host/port or in a Unix filesystem path, dependent on its type.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.socket-getpeername-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">socket</code></dt>

     <dd>

      <p class="para">
       A valid socket resource created with <span class="function"><a href="socket_create.html" class="function">socket_create()</a></span>
       or <span class="function"><a href="socket_accept.html" class="function">socket_accept()</a></span>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">address</code></dt>

     <dd>

      <p class="para">
       If the given socket is of type <strong><code>AF_INET</code></strong> or
       <strong><code>AF_INET6</code></strong>, <span class="function"><strong>socket_getpeername()</strong></span>
       will return the peers (remote) <em class="emphasis">IP address</em> in
       appropriate notation (e.g. <em>127.0.0.1</em> or
       <em>fe80::1</em>) in the <code class="parameter">address</code>
       parameter and, if the optional <code class="parameter">port</code> parameter is
       present, also the associated port.
      </p>
      <p class="para">
       If the given socket is of type <strong><code>AF_UNIX</code></strong>,
       <span class="function"><strong>socket_getpeername()</strong></span> will return the Unix filesystem
       path (e.g. <em>/var/run/daemon.sock</em>) in the
       <code class="parameter">address</code> parameter.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">port</code></dt>

     <dd>

      <p class="para">
       If given, this will hold the port associated to
       <code class="parameter">address</code>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.socket-getpeername-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。 <span class="function"><strong>socket_getpeername()</strong></span> may also return
   <strong><code>FALSE</code></strong> if the socket type is not any of <strong><code>AF_INET</code></strong>,
   <strong><code>AF_INET6</code></strong>, or <strong><code>AF_UNIX</code></strong>, in which
   case the last socket error code is <em class="emphasis">not</em> updated.
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.socket-getpeername-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    <span class="function"><strong>socket_getpeername()</strong></span> should not be used with
    <strong><code>AF_UNIX</code></strong> sockets created with <span class="function"><a href="socket_accept.html" class="function">socket_accept()</a></span>.
    Only sockets created with <span class="function"><a href="socket_connect.html" class="function">socket_connect()</a></span> or a primary
    server socket following a call to <span class="function"><a href="socket_bind.html" class="function">socket_bind()</a></span> will return
    meaningful values.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    For having <span class="function"><strong>socket_getpeername()</strong></span> to return a meaningful value,
    the socket it is applied upon must of course be one for which the concept of 
    &quot;peer&quot; makes sense.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.socket-getpeername-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="socket_getsockname.html" class="function" rel="rdfs-seeAlso">socket_getsockname()</a> - Queries the local side of the given socket which may either result in host/port or in a Unix filesystem path, dependent on its type</span></li>
    <li class="member"><span class="function"><a href="socket_last_error.html" class="function" rel="rdfs-seeAlso">socket_last_error()</a> - Returns the last error on the socket</span></li>
    <li class="member"><span class="function"><a href="socket_strerror.html" class="function" rel="rdfs-seeAlso">socket_strerror()</a> - Return a string describing a socket error</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>